package org.coderfun.fieldmeta.web.member;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import klg.common.model.EasyUIPage;
import klg.common.model.JsonData;

import org.coderfun.member.core.aop.MemberInject;
import org.coderfun.member.core.aop.MemberValid;
import org.coderfun.workspace.entity.Workspace;
import org.coderfun.workspace.service.WorkspaceService;



/**
 *
 * 
 * Generated by fieldmeta at 2018-12-12T13:01:49+08:00
 *
 */

@Controller("adminWorkspaceController")
@RequestMapping("/admin/action/workspace")
public class WorkspaceController {
	@Autowired
	WorkspaceService workspaceService;
	
	@ResponseBody
	@RequestMapping("/add")
	public JsonData add(
			@MemberInject @ModelAttribute Workspace workspace){
		
		workspaceService.save(workspace);
		return JsonData.success();
	}
	
	@MemberValid(entityClass = Workspace.class,entityIdValueArg = "workspace.id")
	@ResponseBody
	@RequestMapping("/edit")
	public JsonData edit(
			@ModelAttribute Workspace workspace){
		
		workspaceService.update(workspace);
		return JsonData.success();
	}
	
	@MemberValid(entityClass = Workspace.class)
	@ResponseBody
	@RequestMapping("/delete")
	public JsonData delete(
			@RequestParam Long id){
		
		workspaceService.delete(id);
		return JsonData.success();
	}
	
	@ResponseBody
	@RequestMapping("/findpage")
	public EasyUIPage findpage(
			@MemberInject @ModelAttribute Workspace workspace,
			@RequestParam int page,
			@RequestParam int rows){
		Pageable pageable=new PageRequest(page<1?0:page-1, rows, new Sort(Direction.DESC,"id"));
		Page<Workspace> pageData=workspaceService.findPage(workspace, pageable);
		return new EasyUIPage(pageData);
	}
	
	@ResponseBody
	@RequestMapping("/findlist")
	public JsonData findlist(
			@MemberInject @ModelAttribute Workspace workspace){
		
		List<Workspace> listData=workspaceService.findList(workspace, new Sort(Direction.DESC,"id"));
		return JsonData.success(listData);
	}	
}
